//李辉负责
(function($, window) {
	var baseRequest = window.baseRequest;
	var appConfig = window.appConfig;
	var commonTool = window.commonTool;
	var dataManager = window.dataManager;
	var baseUrl = appConfig.v3ServiceUrl + '/ant';

	var v3AntService = window.v3AntService = {};

	//add by dongjuanying

	//end

	//add by wangyu
	var mantanceLog = baseUrl + '/read_logmgr';
	v3AntService.getMantanceLog = function(devSN, startTime, endTime, callback){
		baseRequest.commonPost(mantanceLog, {
			devSN: devSN,
			startTime: startTime,
			endTime: endTime,
			method: 'getLog',
			ret: []
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.retCode === 0){
					callback(0,data.message);
				}else{
					callback(1);
				}
			}
		})
	}
	
	var configuration = baseUrl + '/rollback';
	v3AntService.getConfiguration = function(devSN, method, callback){
		baseRequest.commonPost(configuration, {
			devSN: devSN,
			method: method
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.reason === ""){
					callback(0,data.result);
				}else{
					callback(1);
				}
			}
		})
	}
	
	v3AntService.deleteConfiguration = function(devSN, fileName, callback){
		baseRequest.commonPost(configuration, {
			devSN: devSN,
			fileName: fileName,
			method: 'deleteCfg'
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.result === "success"){
					callback(0, data);
				}else{
					callback(1);
				}
			}
		})
	}
	
	v3AntService.addConfiguration = function(devSN, createTime, fileName, reason, callback){
		baseRequest.commonPost(configuration, {
			devSN: devSN,
			cfgTimeout: '300',
			createTime: createTime,
			deviceModule: 'ROLLBACK',
			method: 'saveCfg',
			opType: 1,
			param: {
				curlTimeout: 60,
				downloadUrl: '/v3/ant/rollback',
				fileName: fileName
			},
			reason: reason
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.errCode === 0){
					callback(0, data);
				}else{
					callback(1);
				}
			}
		})
	}
	
	v3AntService.reduceConfiguration = function(devSN, fileSize, fileName, reason, rollbackTime, callback){
		baseRequest.commonPost(configuration, {
			devSN: devSN,
			cfgTimeout: '300',
			deviceModule: 'ROLLBACK',
			method: 'rollbackCfg',
			param: {
				curlTimeOut: 60,
				downloadUrl: '/download/fileName',
				fileName: fileName,
				fileSize: fileSize
			},
			reason: reason,
			rollbackTime: rollbackTime
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.errCode === 0){
					callback(0, data);
				}else{
					callback(1);
				}
			}
		})
	}

	//end

	//add by ding
	//批量获取场所健康度
	var getHealthOfShopsUrl = baseUrl + "/oasishealth";
	v3AntService.getHealthOfShops = function(shopIds,callback){
		baseRequest.commonPost(getHealthOfShopsUrl, {
			method:"getScenarioHealthScoreToApp",
			scenarioId:shopIds
		}, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.message === "success"){
					callback(0,data.Info);
				}else{
					callback(1);
				}
			}
		});
	}
	
	var natDetectUrl = baseUrl + "/nat_detect";
	v3AntService.natDetect = function(devSN, callback) {
		//console.log(JSON.stringify(data));
		
		var para = {
			Method: 'GetActiveClient',
			Param: {
				ACSN: devSN
			},
			Return: [
				"APName",
				"ClientMAC",
				"FirstTime",
				"LastTime",
				"DetectTimes",
				"OSVersion"
			]
		};
		baseRequest.commonPost(natDetectUrl, para, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.retCode === 0) {
					callback(0, data.message);
				} else {
					callback(1);
				}
			}
		});
	}

	var readWipsApUrl = baseUrl + '/read_wips_ap';
	v3AntService.readWipsAp = function(devSN, callback) {
		var para = {
			Method: 'GetRogueAp',
			Param: {
				ACSN: devSN
			},
			Return: [
				"APName",
				"MacAddress",
				"SeverityLevel"
			]
		};
		baseRequest.commonPost(readWipsApUrl, para,10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.retCode === 0) {
					callback(0, data.message);
				} else {
					callback(1);
				}
			}
		});
	}
	//end

})(mui, window);